import os
from copy import deepcopy
no_file="There is nothing to search"
file="um_db.txt"
serch=[] # this will contain the list of keywords to be searched

####################################################################
def fn_search():
  tup=[];
  temp="";
  b=False;
  for line in open(file):
    line=line.strip()
    

    if(cmp(line,"")==0):
      continue
      
    

    if(cmp(line,"<*entry*>")==0):
      if(b==False):
	b=True;
      else:
	b=False;
    
  
    if(b):
      b=False;
      if(cmp(temp,"")==0):
	continue
      else:
	tup.append(temp)
	temp=""
    else:
      temp=temp+line;
      
 
  
  
  keyword(tup)


####################################################################
def prelim_check():
  if(os.path.isfile(file)==True):
    fn_search()
  else :
    print no_file


####################################################################
def keyword(tup):
  
  final=[]
  for tp in tup: 
    str=tp
    w="<*keyword*>"
    w1="<*/keyword*>"
    w2="<*/keywords*>"
    w3="<*url*>"
    w4="<*/url*>"
    key=[]
    
    while(True):
      r=str.find(w)
      r1=str.find(w1)
      #str=str[r:]
      temp=str[r+len(w):r1]
      str=str[r1+len(w1):]
      key.append(temp)
      
      if(str.index(w2)==0):
	break;
      else:
	continue
    count=0
    for k in key :
      for j in serch:
	if(k==j):
	  count=count + 1
	  
	else:
	  continue
    
    final.append(count)
  
  #print final
  url(tup,final)

####################################################################


def url(tup,final):
  #print tup
  tup= geturl(tup)
  temp=deepcopy(final)
  temp.sort()
  temp.reverse()
  
  for i in temp:
    if(cmp(i,0)>0):
      print tup[final.index(i)]+"\t\t\t\t keywords matched="+str(i)
      final[final.index(i)]=-1 # this is to get the next index if count value of kwywords for 2 url is the same
      
    
  

  





####################################################################

def geturl(tup):
  temp=[];
  for i in tup:
    r=i.find("<*url*>")
    r1=i.find("<*/url*>")
    url=i[r+len("<*url*>"):r1]
    temp.append(url)
  return temp
    




####################################################################






if __name__=='__main__':
  search=raw_input("Input all the keywords to search:\n")
  serch=search.split()
  prelim_check();